<?php

namespace App\Domain\LifeHealth\Dao;

use App\Domain\LifeHealth\Models\SleepingModel;
use App\Domain\LifeHealth\Models\SmokeModel;
use App\Domain\LifeHealth\Models\SportModel;
use App\Domain\LifeHealth\Models\DrinkModel;
use App\Domain\LifeHealth\Models\FlavorModel;

class LifeHealthDao
{
    public function findBySmokeUid($uid)
    {
        $data = SmokeModel::where('uid', $uid)->first();
        return $data;
    }

    public function findBySportUid($uid)
    {
        $data = SportModel::where('uid', $uid)->first();
        return $data;
    }

    public function findBySleepUid($uid)
    {
        $data = SleepingModel::where('uid', $uid)->first();
        return $data;
    }

    public function findByDrinkUid($uid)
    {
        $data = DrinkModel::where('uid', $uid)->first();
        return $data;
    }

    public function findByFlavorUid($uid)
    {
        $data = FlavorModel::where('uid', $uid)->first();
        return $data;
    }

    /**
     * 修改吸烟记录
     * @param SmokeModel $model
     * @param $param
     * @return SmokeModel
     */
    public function updateSmoke(SmokeModel $model, $param)
    {
//        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建吸烟记录
     * @param $params
     * @return SmokeModel
     */
    public function createSmoke($params)
    {
//        $params = array_filter_null($params);
        return SmokeModel::create($params);
    }

    /**
     * 修改运动记录
     * @param SportModel $model
     * @param $param
     * @return SportModel
     */
    public function updateSport(SportModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建运动记录
     * @param $params
     * @return SportModel
     */
    public function createSport($params)
    {
        $params = array_filter_null($params);
        return SportModel::create($params);
    }

    /**
     * 修改睡眠记录
     * @param SleepingModel $model
     * @param $param
     * @return SleepingModel
     */
    public function updateSleep(SleepingModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建睡眠记录
     * @param $params
     * @return SleepingModel
     */
    public function createSleep($params)
    {
        $params = array_filter_null($params);
        return SleepingModel::create($params);
    }

    /**
     * 修改饮酒记录
     * @param DrinkModel $model
     * @param $param
     * @return DrinkModel
     */
    public function updateDrink(DrinkModel $model, $param)
    {
//        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建饮酒记录
     * @param $params
     * @return DrinkModel
     */
    public function createDrink($params)
    {
//        $params = array_filter_null($params);
        return DrinkModel::create($params);
    }

    /**
     * 修改饮食记录
     * @param FlavorModel $model
     * @param $param
     * @return FlavorModel
     */
    public function updateFlavor(FlavorModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建饮食记录
     * @param $params
     * @return FlavorModel
     */
    public function createFlavor($params)
    {
        $params = array_filter_null($params);
        return FlavorModel::create($params);
    }

}
